﻿using System;
using System.Web.UI.WebControls;

public partial class aspx_admin_news_view : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        Response.Redirect(string.Format("edit.aspx?id={0}", this.GridView1.Rows[e.NewEditIndex].Cells[1].Text));
    }

    protected void btn全选_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow item in this.GridView1.Rows)
        {
            (item.FindControl("ccb选择") as CheckBox).Checked = true;
        }
    }

    protected void btn置顶_Click(object sender, EventArgs e)
    {
        setding(true);
    }

    protected void btn新_Click(object sender, EventArgs e)
    {
        setnew(true);
    }

    protected void btn显示_Click(object sender, EventArgs e)
    {
        setvisable(true);
    }

    protected void btn取消置顶_Click(object sender, EventArgs e)
    {
        setding(false);
    }

    protected void btn取消new_Click(object sender, EventArgs e)
    {
        setnew(false);
    }

    protected void btn取消显示_Click(object sender, EventArgs e)
    {
        setvisable(false);
    }
    protected void ddl分页_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.GridView1.PageSize = int.Parse(ddl分页.SelectedItem.Text);
        this.GridView1.DataBind();
    }
    protected void btn删除所选项_Click(object sender, EventArgs e)
    {
        bool flag = true;
        foreach (GridViewRow item in this.GridView1.Rows)
        {
            CheckBox ccb = item.FindControl("ccb选择") as CheckBox;
            if (ccb.Checked)
            {
                flag = false;
                using (ds_名师讲堂TableAdapters.tb_通知公告TableAdapter da = new ds_名师讲堂TableAdapters.tb_通知公告TableAdapter())
                {
                    da.Delete(int.Parse(ccb.ToolTip));
                }
            }
        }
        if (flag)
        {
            WebHelper.MessageBox.Show("请选择相应的条目再进行操作。");
        }
        this.GridView1.DataBind();
    }

    protected void btn设置重要性_Click(object sender, EventArgs e)
    {
        decimal point;
        if (!decimal.TryParse(txt重要性.Text, out point))
        {
            WebHelper.MessageBox.Show("请输入一个整数");
            return;
        }
        bool flag = true;
        foreach (GridViewRow item in this.GridView1.Rows)
        {
            CheckBox ccb = item.FindControl("ccb选择") as CheckBox;
            if (ccb.Checked)
            {
                flag = false;
                using (ds_名师讲堂TableAdapters.tb_通知公告TableAdapter da = new ds_名师讲堂TableAdapters.tb_通知公告TableAdapter())
                {
                    da.Update设置重要性(point, int.Parse(ccb.ToolTip));
                }
            }
        }
        if (flag)
        {
            WebHelper.MessageBox.Show("请选择相应的条目再进行操作。");
        }
        this.GridView1.DataBind();
    }

    private void setvisable(bool b)
    {
        bool flag = true;
        foreach (GridViewRow item in this.GridView1.Rows)
        {
            CheckBox ccb = item.FindControl("ccb选择") as CheckBox;
            if (ccb.Checked)
            {
                flag = false;
                using (ds_名师讲堂TableAdapters.tb_通知公告TableAdapter da = new ds_名师讲堂TableAdapters.tb_通知公告TableAdapter())
                {
                    da.Update设置显示(b, int.Parse(ccb.ToolTip));
                }
            }
        }
        if (flag)
        {
            WebHelper.MessageBox.Show("请选择相应的条目再进行操作。");
        }
        this.GridView1.DataBind();
    }

    private void setnew(bool b)
    {
        bool flag = true;
        foreach (GridViewRow item in this.GridView1.Rows)
        {
            CheckBox ccb = item.FindControl("ccb选择") as CheckBox;
            if (ccb.Checked)
            {
                flag = false;
                using (ds_名师讲堂TableAdapters.tb_通知公告TableAdapter da = new ds_名师讲堂TableAdapters.tb_通知公告TableAdapter())
                {
                    da.Update设置new(b, int.Parse(ccb.ToolTip));
                }
            }
        }
        if (flag)
        {
            WebHelper.MessageBox.Show("请选择相应的条目再进行操作。");
        }
        this.GridView1.DataBind();
    }

    private void setding(bool b)
    {
        bool flag = true;
        foreach (GridViewRow item in this.GridView1.Rows)
        {
            CheckBox ccb = item.FindControl("ccb选择") as CheckBox;
            if (ccb.Checked)
            {
                flag = false;
                using (ds_名师讲堂TableAdapters.tb_通知公告TableAdapter da = new ds_名师讲堂TableAdapters.tb_通知公告TableAdapter())
                {
                    da.Update设置置顶(b, int.Parse(ccb.ToolTip));
                }
            }
        }
        if (flag)
        {
            WebHelper.MessageBox.Show("请选择相应的条目再进行操作。");
        }
        this.GridView1.DataBind();
    }

    protected void HyperLink1_DataBinding(object sender, EventArgs e)
    {
        HyperLink hy = sender as HyperLink;
        if (hy.Text.Length > 26)
        {
            hy.Text = string.Format("{0}...", hy.Text.Substring(0, 26));
        }
    }
    protected void btn红字_Click(object sender, EventArgs e)
    {
        setred(true);
    }

    protected void btn取消红字_Click(object sender, EventArgs e)
    {
        setred(false);
    }

    private void setred(bool b)
    {
        bool flag = true;
        foreach (GridViewRow item in this.GridView1.Rows)
        {
            CheckBox ccb = item.FindControl("ccb选择") as CheckBox;
            if (ccb.Checked)
            {
                flag = false;
                {
                    using (ds_名师讲堂TableAdapters.tb_新闻中心TableAdapter da = new ds_名师讲堂TableAdapters.tb_新闻中心TableAdapter())
                        da.Update设置红字(b, int.Parse(ccb.ToolTip));
                }
            }
        }
        if (flag)
        {
            WebHelper.MessageBox.Show("请选择相应 的条目再进行操作。");
        }
        this.GridView1.DataBind();
    }
}